package insight.google.game.era.bo.policy.gamecard;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import insight.google.game.era.bo.GameActionLog;
import insight.google.game.era.bo.GameRoom;
import insight.google.game.era.bo.GameUser;
import insight.google.game.era.bo.card.GameCard;
import insight.google.game.era.bo.policy.AbstractPolicy;
import insight.google.game.era.bo.policy.PolicyCenter;
import insight.google.game.era.client.proxy.PlayerClientProxy;
import insight.google.game.era.client.proxy.PlayerClientProxyImpl;
import insight.google.game.era.core.Util;
import insight.google.game.era.mgr.GameLogManager;

public class ForeignEnemyInvasionPolicy extends AbstractPolicy {

	private PlayerClientProxy playerClientProxy;

	@Override
	public boolean execute(GameUser original, GameUser[] targets, Map params) {
		// TODO Auto-generated method stub
    	//started monirul for game log
    	GameRoom currentRoom = (GameRoom)original.getCurrentRoom();
    	//GameLogManager gameLogManager = currentRoom.getGameLogManager();
    	//ended monirul for game log
        playerClientProxy = PlayerClientProxyImpl.getInstance();
        
        Collection<GameUser> userList = currentRoom.getUserList();

        PolicyCenter pCenter = PolicyCenter.getInstance();
        System.out.println("PolicyCenter " + pCenter.toString());
        for(GameUser trgUser : userList){
            System.out.println("original.getName() " + original.getName());
            System.out.println("trgUser.getName() " + trgUser.getName());

            currentRoom.putTask(original, trgUser, PolicyCenter.CARD_TYPE_FOREIGN_ENEMY_INVASIO, PolicyCenter.CARD_TYPE_ATTACK);

            //get match data 
            String cardName= (String)params.get("cardName");
            Map matchData = (Map)pCenter.getPolicyDataMap(cardName);
            String matchMethod = (String)matchData.get(PolicyCenter.KEY_METHOD);
            //get js component id
            String jsComponentId = (String)params.get("jsComponenetId");

            //set target user active card
            List<String> activeCards = new ArrayList<String>();
            activeCards.add("attack");
//            trgUser.setActiveCards(activeCards);
//            playerClientProxy.setActiveCard(trgUser.getScriptProxy(), jsComponenetId, trgUser.getActiveCards());
//            
//            //set target user active
//            playerClientProxy.setActive(trgUser.getScriptProxy(), jsComponenetId, true);
//            //let target user do match card
//            //playerClientProxy.attackCardPolicyExe(trgUser.getScriptProxy(), jsComponenetId, matchMethod, original.getName(), cardName);
//            playerClientProxy.duelCardPolicyExe(trgUser.getScriptProxy(), jsComponenetId, matchMethod, original.getName(), cardName);
            trgUser.setActiveCards(activeCards,jsComponentId);
            trgUser.setClientActive(true, jsComponentId);
            trgUser.dualCardPolicyExecute(cardName, jsComponentId, matchMethod, original.getName());
            //gameLogManager.addGameLog(new GameActionLog(original.getName() + " attacked user "+ trgUser.getName()));
            
            
        }
        return true;
	}

}
